package com.ruoyi.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.course.domain.SCourse;
import com.ruoyi.course.service.ITCourseService;
import com.ruoyi.course.vo.SCourseVo;
import com.ruoyi.course.mapper.SCourseMapper;
import com.ruoyi.course.service.ISCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生课程Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Service
public class SCourseServiceImpl extends ServiceImpl<SCourseMapper, SCourse> implements ISCourseService {

    @Autowired
    ITCourseService tCourseService;
    @Override
    public TableDataInfo<SCourseVo> queryList(SCourseVo entity) {
        Page<SCourseVo> sCourseVoPage = this.baseMapper.queryList(PageUtils.buildPage(), entity);
        List<SCourseVo> records = sCourseVoPage.getRecords();
        for (SCourseVo record : records) {
            String courseName=null;
            LambdaQueryWrapper<SCourse> sqw = new LambdaQueryWrapper<>();
            sqw.eq(SCourse::getId,record.getId());
            SCourse sCourse = this.baseMapper.selectOne(sqw);
            if(sCourse!=null){
                courseName = tCourseService.queryById(sCourse.getCId()).getName();
            }
            record.setCourseName(courseName);
        }
        return PageUtils.buildDataInfo(sCourseVoPage);
    }

    @Override
    public List<SCourseVo> queryAll(SCourseVo entity) {
        return this.baseMapper.queryList(entity);
    }

    @Override
    public SCourseVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }
}
